import 'package:code_preview/code_preview.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shimmer/shimmer.dart';
import 'package:study_demo/ui/shimmer/shimmer_controller.dart';

import '../../res/image.gen.dart';

class ShimmerPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<ShimmerController>(
        init: ShimmerController(),
        builder: (controller) {
          return Scaffold(
              appBar: AppBar(
                title: Text('shimmer'),
                actions: [
                  TextButton(
                      onPressed: () {
                        controller.showCode();
                      },
                      child: Text(
                        !controller.isShow.value ? '查看源码' : '隐藏源码',
                        style: TextStyle(color: Colors.white),
                      ))
                ],
              ),
              body: SingleChildScrollView(
                  child: Column(
                children: [
                  Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.only(bottom: 10),
                      child: SizedBox(
                          width: 200.0,
                          height: 100.0,
                          child: Shimmer.fromColors(
                              baseColor: Colors.red,
                              highlightColor: Colors.white,
                              child: Image(
                                  image: AssetImage(ImageRes.yinzhi_log))))),
                  Offstage(
                      offstage: !controller.isShow.value,
                      child: CodePreview(className: 'ShimmerPage'))
                ],
              )));
        });
  }
}
